package com.bawei.composeui2207a.day02

import androidx.compose.foundation.Image
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.bawei.composeui2207a.R
import com.bawei.composeui2207a.view.HomePage
import com.bawei.composeui2207a.view.MessagePage
import com.bawei.composeui2207a.view.MinePage

/**
 * 作者：赵亮
 * 时间：2024/12/11 16:46
 * 功能：底部导航
 */
// 底部导航数据类
data class BottomEntity(val img: Int, val text: String)

@Composable
fun Page12() {

    val list = listOf(
        BottomEntity(R.drawable.icon1275, "消息"),
        BottomEntity(R.drawable.icon64, "门户"),
        BottomEntity(R.drawable.icon1405, "我的"),
    )

    /**
     * 底部导航默认选中哪一个
     */
    var selectIndex by remember {
        mutableStateOf(1)
    }

    Scaffold(
        bottomBar = {
            NavigationBar {
                list.forEachIndexed { index, bottomEntity ->
                    NavigationBarItem(
                        selected = selectIndex == index,
                        onClick = { selectIndex = index },
                        icon = {
                            Image(
                                painter = painterResource(id = bottomEntity.img),
                                contentDescription = null
                            )
                        }, label = { Text(text = bottomEntity.text) })
                }
            }
        }
    ) {
        when(selectIndex) {
            0-> MessagePage()
            1-> HomePage()
            2-> MinePage()
        }
    }
}

@Preview(showSystemUi = true)
@Composable
fun Page12Preview() {
    Page12()
}

